package com.sanjiahantang.youjiarole.module.decorate.views.impl;


import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpFragment;
import com.sanjiahantang.youjiarole.module.decorate.presenters.DecorateManagePresenter;
import com.sanjiahantang.youjiarole.module.decorate.views.DecorateManageView;


/**
 * Created by zy on 2017/8/11.
 */

public class DecorateManageFragment extends BaseMvpFragment<DecorateManageView,DecorateManagePresenter> implements DecorateManageView,View.OnClickListener{


    private TextView txtTitle;
    private ImageView ivBack;
//    private RadioGroup rgTabs;
    private View $view;
    private static FragmentManager fMgr;
    private FragmentTransaction ft;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if ($view != null) {
            ViewGroup parent = (ViewGroup) $view.getParent();
            if (parent != null) {
                parent.removeView($view);
            }
        } else {
            $view = inflater.inflate(R.layout.fragment_decorate_manage, container, false);
        }
        return $view;
    }

    @Override
    public DecorateManagePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        txtTitle = (TextView) $view.findViewById(R.id.title);
        ivBack = (ImageView) $view.findViewById(R.id.back);
//        rgTabs = (RadioGroup) $view.findViewById(R.id.rgTabs);
        fMgr = context.getSupportFragmentManager();
    }


    private void initFragment(String tag) {
//        FragmentTransaction ft = fMgr.beginTransaction();
//        DecorateDetailActivity innerPageFragment=new DecorateDetailActivity();
//        ft.add(R.id.mainContents, innerPageFragment, tag);
//        ft.addToBackStack(tag);
//        ft.commit();
    }

    @Override
    protected void initData() {
        txtTitle.setText("装修管理");
        ivBack.setOnClickListener(DecorateManageFragment.this);
//        for(int i = 0;i < 13;i++){
//            RadioButton rb = getRadio("装修名称" + (i + 1),"信息" + (i + 1));
//            rgTabs.addView( rb );
//            if(i==0){
//                rgTabs.check(rb.getId());
//            }
//        }
//        rgTabs.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
//                RadioButton rb = (RadioButton) rgTabs.findViewById(checkedId);
//                changeFragment(rb.getTag().toString());
//            }
//        });

        initFragment("信息1");
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                //FIXME 首页回第一个fragment

                break;
        }
    }

    private RadioButton getRadio(String name, String msg){
        RadioButton rb = (RadioButton) LayoutInflater.from(context).inflate(R.layout.item_radio_cell,null);
        rb.setText(name);
        rb.setTag(msg);
        return rb;
    }


    @Override
    public void showProgress() {
        context.showProgress(context);
    }

    @Override
    public void hideProgress() {
        context.hideProgress();
    }

    @Override
    public DecorateManagePresenter getPresenter() {
        return new DecorateManagePresenter();
    }
}
